package utils
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	import flash.utils.ByteArray;
	import flash.utils.Dictionary;
	import flash.utils.getDefinitionByName;
	import XComponent.hide.XEvent;
	
	public class LoadFile extends EventDispatcher
	{
		private var _loader:Loader;
		private var _tileTypes:Object;
		private var _context : LoaderContext;
		
		public function LoadFile()
		{
			_tileTypes = new Object();
		}
		/**
		 * Loads a text file from the specified url.
		 * @param url The location of the text file to load.
		 */
		public function loadFile(url:String,type:String=null):void
		{
			_loader = new Loader();
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
			
			_context = new LoaderContext(false,ApplicationDomain.currentDomain);
			_loader.load(new URLRequest(url),_context);
		}
		
		/**
		 * Parses text file into tile definitions and map.
		 */
		private function onLoad(event:Event):void
		{
			dispatchEvent(new XEvent(Event.COMPLETE,_loader));
		}
	}
}

